package com.yeren.servlet.tarena.web;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LifeServlet extends HttpServlet {
	// 阶段1：实例化
	public LifeServlet() {
		System.out.println("1.Construct is running...");
	}

	// 阶段2：初始化
	public void init() throws ServletException {
		System.out.println("2.Init is running...");
	}

	// 阶段3：就绪
	public void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// 读取初始化参数
		ServletConfig config = getServletConfig();
		String name = config.getInitParameter("company");
		String address = config.getInitParameter("address");
		System.out.println("servlet is running...");
		System.out.println("初始化参数为：" + name + " " + address);
	}
	//阶段4：销毁
	public void destroy(){
		super.destroy();
		System.out.println("4.Destroy is running...");
	}
}
